package com.ymatou.iapi.productmanager.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.UnLinkSpuProductBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.GetProductAndCatalogInfoCall;
import com.ymatou.iapi.productmanager.service.UnLinkSpuProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
/**
*解除关联商品库Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnLinkSpuProduct{
	private static UnLinkSpuProductBean unlinkspuproductBean;
	private static UnLinkSpuProductCall unlinkspuproductCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解除关联商品库Test");
	}

	@Before
	public void caseUp() {
		unlinkspuproductBean=new UnLinkSpuProductBean();
		unlinkspuproductCall=new UnLinkSpuProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unlinkspuproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UnLinkSpuProduct_001() {
		Logger.start(true,"正确数据，成功");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerSpuProduct(3383);
			String ProductId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Thread.sleep(3000);
			
			unlinkspuproductBean.setSellerId(3383);
			unlinkspuproductBean.setProductId(ProductId);
			unlinkspuproductCall.setData(unlinkspuproductBean);
			unlinkspuproductCall.callService();			
			Logger.verifyEquals("200", unlinkspuproductCall.getString("Code"), "验证code");
			JSONObject ret = new GetProductAndCatalogInfoCall().callAndGetReturnData(3383, ProductId);
			Logger.verifyEquals(0,ret.getJSONObject("Data").getJSONObject("ProductAndCatalogInfoOnSellerProduct").getInt("SpuProductId"),"验证SpuProductId");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}